{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "80097d8e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "xinyi\n",
      "123456\n",
      "20\n"
     ]
    }
   ],
   "source": [
    "users_list = [\"xinyi\",\"yang\",\"ming\"]\n",
    "password_list = [123456,234567,345678]\n",
    "age_list = [20,19,18]\n",
    "print(users_list[0])\n",
    "print(password_list[0])\n",
    "print(age_list[0])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "fc3bf1d3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['xinyi', 123456, 20]\n"
     ]
    }
   ],
   "source": [
    "# 列表的嵌套\n",
    "info_list = [[\"xinyi\",123456,20],[\"yang\",234567,19]]\n",
    "print(info_list[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "3b565605",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mary', 'Jan']\n",
      "['Mike', 'Mary']\n",
      "['Mike', 'Mary']\n"
     ]
    }
   ],
   "source": [
    "# slices(切片) 数值是指 values 在 list 中的位置\n",
    "\n",
    "# 1. 正向取值 (list 取值 “:”右边的值取不到 例如[1:3] 3 这个位置取不到)\n",
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "print(names[1:3])\n",
    "print(names[0:2])\n",
    "\n",
    "# 如果 左侧的值是0 即从0开始取值，0可以省略不写\n",
    "print(names[:2])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "f9957a20",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "妈妈\n"
     ]
    }
   ],
   "source": [
    "# 例子 取出“妈妈”\n",
    "dd = \"听妈妈的话别让她受伤\"\n",
    "print(dd[1:3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "00f1f3c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mary', 'Jan', 'Jack']\n"
     ]
    }
   ],
   "source": [
    "# 2. 反向取值\n",
    "# list 取值 “:”右边的值取不到 \n",
    "# 注意： 要取最后一个值，直接省略不写即可,不能写 0\n",
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "print(names[-3:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "647af278",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "妈妈\n"
     ]
    }
   ],
   "source": [
    "# 例子 取出“妈妈”\n",
    "dd = \"听妈妈的话别让她受伤\"\n",
    "print(dd[-9:-7])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "a0ab9e07",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 3, 5]\n",
      "[0, 1, 2, 3, 4, 5, 6, 7, 8]\n"
     ]
    }
   ],
   "source": [
    "num = [1,2,3,4,5,6,7,8,9]\n",
    "print(num[:6:2]) # 指从 0 到 6 的字符每隔两个取一个，第七个取不到\n",
    "\n",
    "# 对比 range\n",
    "print(list(range(9)))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
